params["_unit","_pos"];

//特殊服装
if(Param_Version > 183) then{
	[_unit] call fn_clearUnit;
	_unit forceAddUniform "U_I_ParadeUniform_01_AAF_decorated_F";
	_unit addHeadgear "H_ParadeDressCap_01_AAF_F";
	_unit addGoggles "G_RegulatorMask_F";
};
//盔甲
_unit addVest "V_PlateCarrierSpec_rgr";

//
_unit setVariable ["as_name", "Garvas", true];
_unit setRank "COLONEL";
//_unit setVariable ["as_level", "上校", true];
as_units_sn pushBack _unit;
publicVariable "as_units_sn";

/*
MP笔记：“杀害”和“命中”事件处理被执行，其中规定的单位是当地的。
所有其他事件处理程序都在所有计算机上执行。在每台计算机上，
由addEventHandler添加的事件可能会有所不同。
*/

/*
if(Param_CarvasNoDead == 1) then
{
	//无敌才移除武器
	removeAllWeapons _unit;
	_unit disableAI "MOVE";
	
}
else
{
*/
//-------------------------------------------------------------------

//给予武器
//[_unit, 6] call fn_initUnit;
//武器
[3, _unit] call fn_initWeapon;
//配件
_unit addPrimaryWeaponItem (selectRandom selectRandom asp_ai_3);
//GF效果
_unit remoteExec ["fn_initUnitLocal", 0];
//移除事件
//_unit removeAllEventHandlers "HandleDamage";
//_unit removeAllEventHandlers "Killed";

//替换头盔
_unit addHeadgear "H_HelmetSpecB";

//-----------这个是本地的shooter必须为本地
[_unit, ["hitpart", 
{
	(_this select 0) params ["_target", "_shooter", "_projectile", "_position", "_velocity", "_selection", "_ammo", "_vector", "_radius", "_surfaceType", "_isDirect"];
	//红军、直接命中
	if (!isNull _shooter
	&& {_isDirect}
	&& {_shooter call fn_isPlayerRed}
	&& {_target distanceSqr _shooter < 90000}
	) then 
	{
		//systemChat "hit"
		if("head" in _selection) then{
			as_npc_damage = as_npc_damage + 24;//此变量不同步也可以
		}else{
			as_npc_damage = as_npc_damage + 5;
		};
		
		_shooter setVariable ["as_kill", (_shooter getVariable ["as_kill", 0]) + 1, true];
		
		_target setDamage (as_npc_damage * 0.01);
	};
}]] remoteExec ["addEventHandler", 0];

//-------------------------------------------------------------------



//死亡镜头 查看n秒后关闭-----------这个是本地的，只需要服务器执行
_unit addEventHandler["killed", { 
	//[_this select 0, 0.5, 3] remoteExec ["fn_camToUnit", 0];
	
	//
	[resistance, "Garvas上校", "这……不可能！（按L查看）"] remoteExec ["fn_talk", 0];
	as_onkeydo_camToUnit = _this select 0;
	publicVariable "as_onkeydo_camToUnit";
	[]spawn{
		Sleep 10;
		as_onkeydo_camToUnit = objNull;
		publicVariable "as_onkeydo_camToUnit";
	};
	
}];

"Gavras上校已被发现..." remoteExec["systemChat", 0];
as_npc = _unit;


//其他方法都不太好用，只能让上校一直循环前往上校点（防止卡墙），除非救援飞机到来
	
//as_npc disableAI "AUTOTARGET";//禁止乱跑
	
as_npc_stop = true;
if(true) then{
	[_unit, _pos] spawn
	{	
		private _unit = _this select 0;
		private _pos = _this select 1;
		private _group = group _unit;
		while{alive _unit && {as_npc_stop}} do
		{
			[_group, _pos, 10] call fn_addWaypoint;
			Sleep 10;
		};		
	};
};


//上校逃跑
[] spawn {
	while{alive as_npc}do
	{
		if((as_npc distance as_end_pos > 1500)
			&& {isNull ([as_npc, 600] call fn_getPlayerNear)})exitWith
		{
			[east, "任务失败", "狡猾的Garvas上校竟从我们眼皮底下溜走了，任务失败！"] remoteExec ["fn_talk", east];
			[resistance, "上校已遁逃", "Garvas上校在我们的掩护下已经脱离了危险，敌人已经是瓮中之鳖！"] remoteExec ["fn_talk", resistance];
		
			as_game_restart = true;
		};
		Sleep 60;
	};
};

//音乐
[] spawn
{
	waitUntil {Sleep 5; !(isNull ([as_npc, 100] call fn_getPlayerNear))};//20
	"Track_R_05" remoteExec ["playMusic"];
	
	//刷一些兵阻碍玩家撤退
	
	//2倍美军
	private _pos = getPos as_npc;
	private _group = [[_pos, 600, 200, false] call fn_getPosNearLand, 2.0, 6, 10, 3] call fn_createGroup;
	_group setVariable["no_cleanup", true];
	[_group, _pos] spawn fn_addWaypoint;

	if(Param_Debug == 0)then{
		//CTRG
		[0, asg_6, _pos, 1000, 0, 1] spawn fn_createGN;
		sleep 15;
		
		//卡车土匪
		[0, asg_4, _pos, 600, 0, 1] spawn fn_createGN;
		sleep 15;
		//卡车土匪
		[0, asg_4, _pos, 600, 0, 1] spawn fn_createGN;
		sleep 15;
		//卡车土匪
		[0, asg_4, _pos, 600, 0, 1] spawn fn_createGN;
		sleep 15;
		
		
		
		sleep 30;
		//武直
		[0, asg_10, _pos, 1200, 0, 1] spawn fn_createGN;
		sleep 15;
		[0, asg_10, _pos, 1200, 0, 1] spawn fn_createGN;
		sleep 15;


		//T-80
		if(Param_RHS == 1) then
		{
			[0, asg_rhs_7, _pos, 1000, 0, 1] spawn fn_createGN;
			sleep 10;
			[0, asg_rhs_7, _pos, 1000, 0, 1] spawn fn_createGN;
			sleep 10;
		}else
		{
		//运兵装甲车
			[0, asg_18, _pos, 1000, 0, 1] spawn fn_createGN;
			sleep 10;
			[0, asg_18, _pos, 1000, 0, 1] spawn fn_createGN;
			sleep 10;
		};
		
		//防空车
		[0, asg_9_1, _pos, 1000, 0, 1] spawn fn_createGN;
		sleep 10;
		
		//固定翼
		[0, selectRandom[asg_21, asg_22], _pos, 1200, 0, 1] spawn fn_createGN;
	};

	[_pos] call fn_createS2; 
	[_pos] call fn_createS2; 
	
	//运输直升机
	if(Param_CarvasMove == 1)then{
		as_npc_stop = false;
		
		private _veh = [_pos, "B_Heli_Transport_03_unarmed_F"] call fn_planeLand; //I_Heli_light_03_dynamicLoadout_F
		private _group = group as_npc;
		private _units = units _group;

		[_group, _veh getPos [5, random 360]] spawn fn_doMove;

		waitUntil{
			Sleep 10;
			if(as_npc distance _veh < 10)then{
				//删除所有路点
				while {(count (waypoints _group)) > 0} do
				{
					deleteWaypoint ((waypoints _group) select 0);
				};

				_group addWaypoint [_veh, 0, 0];
				_units allowGetIn true;
				[_group, 0] waypointAttachVehicle _veh;
				[_group, 0] setWaypointType "GETIN";
			};
			(!alive _veh) || {!alive as_npc} || {vehicle as_npc == _veh}
		};

		
		if(alive _veh
		&& {alive as_npc})then{
					
			//动画
			[as_npc, 1.5, 3, 3.5] remoteExec["fn_camToUnit", 0];
			[resistance, "Garvas上校", "再见，朋友们！"] remoteExec ["fn_talk", 0];
		
			while{true}do{
				Sleep 10;
				if(isNull (driver _veh) || {!alive driver _veh})then{moveOut as_npc; as_npc moveInDriver _veh;};
				_veh flyInHeight 100;
				_veh engineOn true;
				_veh move [-1000, -1000, 100];
			};
		};
	}
};

[as_npc, 3, true] spawn fn_bomberAI;

waitUntil{Sleep 5;!alive as_npc};


//[resistance, "Garvas上校", "……"] remoteExec ["fn_talk", 0];
"Gavras上校死亡..." remoteExec["systemChat", 0];

//让上校死得安详
as_npc setMimic "dead";

as_npc_dead = true;
publicVariable "as_npc_dead";


deleteMarker "mk_end";


